package com.sgb.jicai.view.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.google.android.material.tabs.TabLayout;
import com.google.gson.Gson;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.entity.LocalMedia;
import com.qgb.zcore.event.WebEvent;
import com.sgb.jicai.R;
import com.sgb.jicai.base.JiCaiBaseApi;
import com.sgb.jicai.databinding.ActivityJoininJicaiBinding;
import com.sgb.jicai.entity.JoinJicaiDetailEntity;
import com.sgb.jicai.entity.SubmitJoininJicaiEntity;
import com.sgb.jicai.event.JiCaiEventEntity;
import com.sgb.jicai.view.fragment.JiCaiQuotedPriceFragment;
import com.sgb.jicai.view.fragment.JoinInPurchaseFragment;
import com.sgb.jicai.view.fragment.JoinRequireFragment;
import com.sgb.jicai.viewmodel.JcChanceListModel;
import com.sgb.jicai.viewmodel.JoinInJiCaiModel;
import com.sgb.link.entity.EventConstant;
import com.swgk.core.base.AppActivity;
import com.swgk.core.util.TimeUtil;
import com.sgb.jicai.view.fragment.JiCaiGuidanceFragment;
import com.swgk.core.view.CityPickBuilder;
import com.swgk.core.view.CityPickView;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.view.areapopup.AddressEntity;
import org.greenrobot.eventbus.EventBus;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 加盟集采--首次加盟
 * 修改加盟信息---复用
 */
public class JoinInJiCaiActivity extends AppActivity implements ItemInputTextView.OnWholeItemClickListener {

    JoinInJiCaiModel model;
    ActivityJoininJicaiBinding binding;
    private String groupbuyingNo;//集采单id
    public static final String KEY_ID = "jicai_id";
    private String participantNo;//加盟单id
    public static final String PARTICIPANT_NO = "participant_id";
    private String jId;//交流id
    public static final String KEY_JILIU_id = "jiaoliu_id";
    // 1.首次加盟   2.修改加盟信息
    private int type;
    public static final String KEY_TYPE = "jicai_joinin_type";
    //地区
    // 一级联动数据
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> addressEntityList;
    //    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> filtrationAddressEntityList;//按省份过滤后的数据
    // 二级联动数据
    private List<List<AddressEntity<List<AddressEntity>>>> opt2 = new ArrayList<>();
    // 三级联动数据
    private List<List<List<AddressEntity>>> opt3 = new ArrayList<>();
    private int cityPosition1;
    private int cityPosition2;
    private int cityPosition3;

    private JoinJicaiDetailEntity detailEntity;
    private String provinceNo;//省级编码
    private String provinceName;//省级名称
    private String cityNo;//城市编码
    private String cityName;//城市名称
    private String districtNo;//区编码
    private String districtName;//区名称

    //集采类型(1是即报即采, 2是汇集采购, 3是企业专项)
    private String groupBuyType;
    public static final String GROUP_BIY_TYPE = "jiCaiGroupBuyType";

    private JoinInPurchaseFragment joinInPurchaseFragment;
    private SubmitJoininJicaiEntity entity;
    private String url = "";

    public static void start(Context context, String id, String participantNo, String jId, int type, String groupBuyType,String url) {
        Intent intent = new Intent();
        intent.putExtra(KEY_ID, id);
        intent.putExtra(PARTICIPANT_NO, participantNo);
        intent.putExtra(KEY_JILIU_id, jId);
        intent.putExtra(KEY_TYPE, type);
        intent.putExtra(GROUP_BIY_TYPE, groupBuyType);
        intent.putExtra("url", url);
        intent.setClass(context, JoinInJiCaiActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        super.initView();
        binding = DataBindingUtil.setContentView(JoinInJiCaiActivity.this, R.layout.activity_joinin_jicai);
        model = new ViewModelProvider(this).get(JoinInJiCaiModel.class);
        url = getIntent().getStringExtra("url");
        model.setActivity(JoinInJiCaiActivity.this);
        binding.ivBack.setOnClickListener(this::onMultiClick);
        binding.tvSubmit.setOnClickListener(this::onMultiClick);
        binding.llJiaoliu.setOnClickListener(this::onMultiClick);
        binding.area.setOnWholeItemClickListener(this);
        entity = new SubmitJoininJicaiEntity();
        String name = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.REAL_NAME, "");
        if (!TextUtils.isEmpty(name)) {
            binding.linkman.setContent(name);
        }
        String tel = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_PHONE, "");
        if (!TextUtils.isEmpty(tel)) {
            binding.linkmanTel.setText(tel);
        }

        String companyNo = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NO, "");
        if (companyNo.equals("") || companyNo.equals("0")) {
            binding.joinCompany.setContent(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.REAL_NAME, ""));
        } else {
            binding.joinCompany.setContent(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NAME, ""));
        }
    }

    /* v1.13改版为多tab */
    private void updateTabFra() {
        ArrayList<Fragment> mFragments = new ArrayList<>();
        mFragments.add(joinInPurchaseFragment);
        mFragments.add(JoinRequireFragment.newInstance(groupbuyingNo, binding.viewpager, 1));
        mFragments.add(JoinRequireFragment.newInstance(groupbuyingNo, binding.viewpager, 2));
        mFragments.add(JiCaiGuidanceFragment.newInstance(groupbuyingNo, binding.viewpager, 3));
        String[] mTitles;
//        if ("2".equals(groupBuyType)) {   //V1。17 需求变更将
//            mTitles = new String[]{"加盟采购量", "加盟规则", "加盟指导"};
//        } else {
        mTitles = new String[]{"加盟采购量", "加盟规则", "集采规则", "加盟指导", "报价列表"};
        mFragments.add(JiCaiQuotedPriceFragment.newInstance(groupbuyingNo, binding.viewpager, 4));
//        }
        SlidingFragmentPagerAdapter mPagerAdapter = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), mFragments, mTitles);
        binding.viewpager.setOffscreenPageLimit(mTitles.length);
        binding.viewpager.setAdapter(mPagerAdapter);
        binding.tabLayout.setupWithViewPager(binding.viewpager);
        binding.tabLayout.setTabMode(mTitles.length > 3 ? TabLayout.MODE_SCROLLABLE : TabLayout.MODE_FIXED);
        binding.viewpager.resetHeight(0);
        binding.tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                int pos = tab.getPosition();
                binding.viewpager.resetHeight(pos);
                binding.viewpager.setCurrentItem(pos);
                if (pos == 0) {
                    binding.tvHint.setVisibility(View.VISIBLE);
                    binding.viewDivision.setVisibility(View.GONE);
                } else {
                    binding.tvHint.setVisibility(View.GONE);
                    binding.viewDivision.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    protected void init() {
        super.init();
        groupbuyingNo = getIntent().getStringExtra(KEY_ID);
        participantNo = getIntent().getStringExtra(PARTICIPANT_NO);
        jId = getIntent().getStringExtra(KEY_JILIU_id);
        type = getIntent().getIntExtra(KEY_TYPE, 1);
        groupBuyType = getIntent().getStringExtra(GROUP_BIY_TYPE);
        if (type == 2) {
            binding.tvTitle.setText("修改加盟信息");
            model.getJicaiJoinDetailDatas(participantNo);   //二次修改信息，先获取内容展示页面
        } else {
            binding.tvTitle.setText("加盟集采");
            model.getDetailData(groupbuyingNo);
        }
        joinInPurchaseFragment = JoinInPurchaseFragment.newInstance(binding.viewpager, 0, this);
        model.getAddressModel();//请求省市区数据
        updateTabFra();
    }

    @Override
    public void onMultiClick(View v) {
        int id = v.getId();
        if (id == R.id.iv_back) {
            if (!TextUtils.isEmpty(url)){
                finish();
                JiCaiBaseApi.startWeb(this,url);
            }else {
                finish();
            }
        } else if (id == R.id.tv_submit) {
            submieJoininDetails();
        } else if (id == R.id.ll_jiaoliu) {
            if (TextUtils.isEmpty(jId)) {
                MToast.showToast(this, "未设置客服人员，不支持交流");
            } else {
                model.findCustomerServiceImAccount(jId);
            }
        }
    }

    private void submieJoininDetails() {
        if (null == detailEntity) {
            return;
        }
        if (TextUtils.isEmpty(cityNo)) {//澳门无区级数据，用市判断
            MToast.showToast(this, "请选择省市区信息");
            return;
        }
        if (TextUtils.isEmpty(binding.etReceiptplace.getEditContent())) {
            MToast.showToast(this, "请填写详细地址");
            return;
        }
        if (TextUtils.isEmpty(binding.principalman.getContent())) {
            MToast.showToast(this, "请填写负责人");
            return;
        }
        if (TextUtils.isEmpty(binding.principalTel.getText().toString().trim())) {
            MToast.showToast(this, "请填写负责人电话");
            return;
        }
        if (!CheckUtils.isMobileNum(binding.principalTel.getText().toString().trim())) {
            MToast.showToast(this, "负责人手机号码填写错误");
            return;
        }
        entity.setReceiptProvinceNo(provinceNo);
        entity.setReceiptProvinceName(provinceName);
        entity.setReceiptCityNo(cityNo);
        entity.setReceiptCityName(cityName);
        entity.setReceiptDistrictNo(districtNo);
        entity.setReceiptDistrictName(districtName);
        entity.setReceiptAddress(binding.etReceiptplace.getEditContent());

        entity.setContacts(binding.linkman.getContent());
        entity.setContactNumber(binding.linkmanTel.getText().toString().trim());
        entity.setDirector(binding.principalman.getContent());
        entity.setDirectorNumber(binding.principalTel.getText().toString().trim());

        entity.setCreateCompany(detailEntity.getCreateCompany());
        entity.setGroupbuyingNo(groupbuyingNo);
        entity.setEmail(binding.principalEmail.getText().toString().trim());
        entity.setId(detailEntity.getId());
        //1.13改版后报价列表信息从fragment中获取并设置
        detailEntity.setGroupbuyingRecordDetailList(joinInPurchaseFragment.getDetailEntity().getGroupbuyingRecordDetailList());
        entity.setRemarks(joinInPurchaseFragment.getDetailEntity().getRemarks());

        if (null != detailEntity.getGroupbuyingRecordDetailList() && detailEntity.getGroupbuyingRecordDetailList().size() > 0) {
            ArrayList<JoinJicaiDetailEntity.RecordDetailListEntity> detailList = detailEntity.getGroupbuyingRecordDetailList();
            List<SubmitJoininJicaiEntity.RecordItemEntity> recordList = new ArrayList<>();
            for (int i = 0; i < detailList.size(); i++) {
                JoinJicaiDetailEntity.RecordDetailListEntity detailListEntity = detailList.get(i);
                SubmitJoininJicaiEntity.RecordItemEntity recordItemEntity = new SubmitJoininJicaiEntity.RecordItemEntity();
                String pickTime = detailListEntity.getPickTime2();//商品的提货时间
                String entranceTime = detailListEntity.getEntranceTime();//非商品的进场时间
                String exitTime = detailListEntity.getExitTime();//非商品的退场时间
                String joinNum = detailListEntity.getOwnNum();
                if (detailList.get(i).getGroupbuyClass() == 1) {//商品
                    if ((TextUtils.isEmpty(pickTime) && !TextUtils.isEmpty(joinNum)) || (!TextUtils.isEmpty(pickTime) && TextUtils.isEmpty(joinNum))) {
                        MToast.showToast(this, "请完善第" + (i + 1) + "个商品的加盟信息");
                        return;
                    }
                } else {//非商品
                    if ((TextUtils.isEmpty(entranceTime) && TextUtils.isEmpty(exitTime) && TextUtils.isEmpty(joinNum)) || (!TextUtils.isEmpty(entranceTime) && !TextUtils.isEmpty(exitTime) && !TextUtils.isEmpty(joinNum))) {

                    } else {
                        MToast.showToast(this, "请完善第" + (i + 1) + "条加盟信息");
                        return;
                    }
                }
                recordItemEntity.setGroupbuyingDetailNo(detailListEntity.getDetailNo());
                recordItemEntity.setPickTime(pickTime);
                recordItemEntity.setEntranceTime(entranceTime);
                recordItemEntity.setExitTime(exitTime);
                recordItemEntity.setViewNum(joinNum);
                recordItemEntity.setGroupbuyClass(detailListEntity.getGroupbuyClass());
                recordItemEntity.setId(detailListEntity.getId());
                try {
                    //判断退场时间需大于进场时间
                    if (!entranceTime.isEmpty() && !exitTime.isEmpty() && TimeUtil.getLongTime(entranceTime, "yyyy-MM-dd") > 100 && TimeUtil.getLongTime(exitTime, "yyyy-MM-dd") > 100) {
                        if (TimeUtil.getLongTime(entranceTime, "yyyy-MM-dd") >= TimeUtil.getLongTime(exitTime, "yyyy-MM-dd")) {
                            if (recordItemEntity.getGroupbuyClass() == 1) {
                                MToast.showToast(this, "第" + (i + 1) + "个商品的退场时间需大于进场时间");
                            } else {
                                MToast.showToast(this, "第" + (i + 1) + "个设备的结束时间需大于入场时间");
                            }
                            return;
                        }
                    }
                } catch (Exception e) {
                }

                recordList.add(recordItemEntity);
            }
            boolean hasJoinData = false;
            //判断至少有一条加盟信息
            for (int i = 0; i < recordList.size(); i++) {
                SubmitJoininJicaiEntity.RecordItemEntity recordItemEntity = recordList.get(i);
                if (!TextUtils.isEmpty(recordItemEntity.getPickTime()) || !TextUtils.isEmpty(recordItemEntity.getEntranceTime())) {//只要有一个提货时间或入场时间证明有至少一条加盟信息
                    hasJoinData = true;
                    break;
                }
            }
            if (!hasJoinData) {
                MToast.showToast(this, "请至少填写一条加盟信息");
                return;
            }
            entity.setGroupbuyingParticipantRecordList(recordList);
        } else {
            MToast.showToast(this, "无加盟信息");
            return;
        }

        model.submitDetailData(entity);
    }

    public void updateView(JoinJicaiDetailEntity detailEntity) {
        this.detailEntity = detailEntity;
        //接口返回值不合规，这里手动修改接口各返回值
        if (type == 1) {//首次加盟
            //将手填项置空
            if (null != detailEntity.getGroupbuyingRecordDetailList() && !detailEntity.getGroupbuyingRecordDetailList().isEmpty()) {
                for (int i = 0; i < detailEntity.getGroupbuyingRecordDetailList().size(); i++) {
//                    detailEntity.getGroupbuyingRecordDetailList().get(i).setExpectPrice("");
                    detailEntity.getGroupbuyingRecordDetailList().get(i).setOwnNum("");
                    detailEntity.getGroupbuyingRecordDetailList().get(i).setPickTime("");
                    detailEntity.getGroupbuyingRecordDetailList().get(i).setEntranceTime("");
                    detailEntity.getGroupbuyingRecordDetailList().get(i).setExitTime("");
                }
            }
        } else if (type == 2) {//修改加盟信息
            binding.linkman.setContent(detailEntity.getContacts());
            binding.linkmanTel.setText(detailEntity.getContactNumber());
            binding.joinCompany.setContent(detailEntity.getCreateCompany());
            jId = detailEntity.getCustomerServiceContactsId();
            //ParticipantId为0时首次没有填写
            if (!detailEntity.getGroupbuyingRecordDetailList().isEmpty()) {
                for (int i = 0; i < detailEntity.getGroupbuyingRecordDetailList().size(); i++) {
                    String participantId = detailEntity.getGroupbuyingRecordDetailList().get(i).getParticipantId();
                    if (null == participantId || participantId.isEmpty() || participantId.equals("0")) {
//                        detailEntity.getGroupbuyingRecordDetailList().get(i).setExpectPrice("");
                        detailEntity.getGroupbuyingRecordDetailList().get(i).setOwnNum("");
                        detailEntity.getGroupbuyingRecordDetailList().get(i).setPickTime("");
                        detailEntity.getGroupbuyingRecordDetailList().get(i).setEntranceTime("");
                        detailEntity.getGroupbuyingRecordDetailList().get(i).setExitTime("");
                    }
                }
            }
            //将值填写到各view
            provinceNo = detailEntity.getReceiptProvinceNo();//省级编码
            provinceName = detailEntity.getReceiptProvinceName();//省级名称
            cityNo = detailEntity.getReceiptCityNo();//城市编码
            cityName = detailEntity.getReceiptCityName();//城市名称
            districtNo = detailEntity.getReceiptDistrictNo();//区编码
            districtName = detailEntity.getReceiptDistrictName();//区名称
            binding.area.setContent(provinceName + "/" + cityName + "/" + districtName);//省市区
            binding.etReceiptplace.setEditContent(detailEntity.getDetailsAddress());
            binding.principalman.setContent(detailEntity.getDirector());
            binding.principalTel.setText(detailEntity.getDirectorNumber());
            binding.principalEmail.setText(detailEntity.getEmail());
          /*  //设置附件回显
            if (detailEntity.getFile()!=null&&detailEntity.getFile().size()>0){
                if (!TextUtils.isEmpty(detailEntity.getFile().get(0).getUrl())&&detailEntity.getFile().get(0).getUrl().contains(".jpg") || detailEntity.getFile().get(0).getUrl().contains(".jpeg") || detailEntity.getFile().get(0).getUrl().contains(".png")){
                    List<LocalMedia> imagelist = new ArrayList<>();
                    LocalMedia localMedia = new LocalMedia();
                    localMedia.setPath(detailEntity.getFile().get(0).getUrl()+"");
                    imagelist.add(localMedia);
                    joinInPurchaseFragment.mPicAdapter.setPicData(imagelist);
                }
            }*/
           /* if (!TextUtils.isEmpty(detailEntity.getFile())){
                List<LocalMedia> imagelist = new ArrayList<>();
                LocalMedia localMedia = new LocalMedia();
                localMedia.setPath(detailEntity.getFile());
                imagelist.add(localMedia);
                joinInPurchaseFragment.mPicAdapter.setPicData(imagelist);
            }*/
        }

        joinInPurchaseFragment.setDetailEntity(detailEntity);

        //列表刷新之后把焦点刷新到最上面
        binding.etReceiptplace.requestFocus();
        binding.svContent.fling(0);
        binding.svContent.smoothScrollTo(0, 0);
    }

    //提交加盟信息成功
    public void submitSucceed() {
        EventBus.getDefault().post(new JiCaiEventEntity(EventConstant.EVENT_WEBVIEW_RELOAD,""));
        WebEvent webEvent = new WebEvent();
        webEvent.setMessageTag(EventConstant.EVENT_WEBVIEW_RELOAD);
        EventBus.getDefault().post(webEvent);
        if (!TextUtils.isEmpty(url)){
            finish();
            JiCaiBaseApi.startWeb(this,url);
        }else {
            finish();
        }
    }

    //返回省市区数据加载数据
    public void initAddressData(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> data) {
        addressEntityList = data;
        initJsonData();
    }

    //组装省市区数据信息
    private void initJsonData() {
        for (int i = 0; i < addressEntityList.size(); i++) {
            ArrayList areaList = new ArrayList<>();
            opt2.add(addressEntityList.get(i).getChildren());
            for (int j = 0; j < addressEntityList.get(i).getChildren().size(); j++) {
                List<AddressEntity> cityAreaList = new ArrayList<>();
                List<AddressEntity> children = addressEntityList.get(i).getChildren().get(j).getChildren();
                if (children == null || children.size() == 0) {
                    cityAreaList.add(null);
                } else {
                    cityAreaList.addAll(children);
                }
                areaList.add(cityAreaList);
            }
            opt3.add(areaList);
        }
    }

    @Override
    public void OnWholeItemClick(View view) {
        if (view.getId() == R.id.area) {//所在地址
            if (addressEntityList != null) {
                showCityPop("请选择地区", 1);
            } else {
                MToast.showToast(this, "获取地区信息出错");
                model.getAddressModel();//请求省市区数据
            }
        }
    }

    //    选择地址弹窗
    private void showCityPop(String title, int num) {
        CityPickView cityOption = new CityPickBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                String areaName = "";
                if (opt3.get(options1).get(options2).get(options3) == null) {
                    areaName = "";
                } else {
                    areaName = opt3.get(options1).get(options2).get(options3).getName();
                    cityPosition3 = options3;
                }
                String content = addressEntityList.get(options1).getName() + " / " + opt2.get(options1).get(options2).getName() + " / " + areaName;
                cityPosition1 = options1;
                cityPosition2 = options2;
                provinceNo = addressEntityList.get(options1).getId();
                provinceName = addressEntityList.get(options1).getName();
                if (opt2.get(options1).get(options2) != null) {
                    cityNo = opt2.get(options1).get(options2).getNo();
                    cityName = opt2.get(options1).get(options2).getName();
                }
                if (opt3.get(options1).get(options2).get(options3) != null) {
                    districtNo = opt3.get(options1).get(options2).get(options3).getNo();
                    districtName = opt3.get(options1).get(options2).get(options3).getName();
                }
                binding.area.setContent(content);
            }
        }).setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setTitleText(title)
                .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD"))
                .build();
        cityOption.setPicker(addressEntityList, opt2, opt3);
        cityOption.setSelectOptions(cityPosition1, cityPosition2, cityPosition3);
        cityOption.show();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            //点击完返回键，执行的动作
            submitSucceed();
        }
        return true;
    }

    public void setPictureSelector() {
        model.pictureSelector(1);
    }

    // 上传图片回调
    public void uploadResult(String filepath) {
        Log.i("uploadAvatarResult", filepath);
        List<SubmitJoininJicaiEntity.FilesBean> files = new ArrayList<>();
        SubmitJoininJicaiEntity.FilesBean bean = new SubmitJoininJicaiEntity.FilesBean();
        int i = filepath.lastIndexOf("/");
        String name = filepath.substring(i+1, filepath.length());
        bean.setName(name);
        bean.setUrl(filepath);
        files.add(bean);
        String file = new Gson().toJson(files);
        entity.setFile(file);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == PictureConfig.CHOOSE_REQUEST) {
                List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                String compressPath = selectList.get(0).getRealPath();
                if (!compressPath.contains("http")){
                    if (compressPath.contains(".jpg") || compressPath.contains(".jpeg") || compressPath.contains(".png")) {
                        File file = new File(compressPath);
                        model.uploadAnnexFileModel(file, 0);
                        MLog.i("file", file.getAbsolutePath());
                        joinInPurchaseFragment.mPicAdapter.setPicData(selectList);
                    } else {
                        MToast.showLongToast(this, "仅支持上传png/jpeg/jpg格式的图片");
                    }
                }

            }
        }
    }
}